package com.mive.repository;

import com.mive.entity.Author;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@CacheConfig
@EnableCaching
public interface AuthorRepository extends JpaRepository<Author, Long> {


    Author findByRealName(String realName);

    Author findByRealNameAndNickName(String realName, String nickName);

    @Cacheable(cacheNames = "realname")
    @Query("select a from Author a where a.realName=?1")
    Author findAuthorByRealName(String realName);

    @Cacheable(cacheNames = "uid")
    @Query("select a from Author a where a.id=:id")
    Author findAuthor(@Param("id") Long id);
}
